<template>
  <el-dialog
    v-el-drag-dialog
    :append-to-body="true"
    title="驳回"
    :visible.sync="visible"
    width="600px"
    @closed="reset"
  >
    <el-form ref="dataForm" class="form" :model="temp" label-position="right" label-width="100px">
      <el-form-item label="驳回原因：" prop="reason">
        <el-input v-model="temp.reason" type="textarea" :rows="3" maxlength="200" show-word-limit />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        取消
      </el-button>
      <el-button :loading="$loadingPlugin.submit" type="primary" @click="success">
        确定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { repairDismissed } from '@/api'

  export default {
    name: 'rejectReason',
    data() {
      return {
        visible: false,
        temp: {
          reason: ''
        }

      }
    },
    methods: {
      open(temp) {
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) { this.currentRow = temp }
        })
      },

      async success() {
        if (!this.temp.reason) {
          this.$message.error('请填写驳回原因')
          return
        }
        const params = {
          repairCode: this.currentRow.repairCode,
          dismissedReason: this.temp.reason
        }
        const res = await repairDismissed(params)
        if (res && res.data) {
          this.resolve()
          this.visible = false
          this.$notify({
            title: '提示',
            message: '操作成功!',
            type: 'success',
            duration: 2000
          })
        }
      },

      reset() {
        this.temp.reason = ''
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
